package com.zjm.session.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author ZJM
 * @date 2024/5/6 22:26
 * 重写URL实现
 */
@WebServlet("/urlSession")
public class UrlSessionServlet extends BaseServlet {

    protected void urlSession(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        String newUrl = resp.encodeRedirectURL("/sessionServlet?action=createOrGetSession");
        System.out.println(newUrl);
        resp.sendRedirect(newUrl);
        System.out.println(session.getId());
    }
}
